<?php
/**
 * 公共函数库
 * @author      HJC <hujianchuang@haowj.com>
 * @update      2014.06.23
 * @since       Version 1.0
 * 
 */

function makeRequest($url, $param, $httpMethod = 'GET') 
{
	$oCurl = curl_init();
	if (stripos($url, "https://") !== FALSE) 
	{
	    curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, FALSE);
	    curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, FALSE);
	}
	if ($httpMethod == 'GET') 
	{
		curl_setopt($oCurl, CURLOPT_URL, $url . "?" . http_build_query($param));
		curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1);
	} 
	else 
	{
		curl_setopt($oCurl, CURLOPT_URL, $url);
		curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($oCurl, CURLOPT_POST, 1);
		curl_setopt($oCurl, CURLOPT_POSTFIELDS, http_build_query($param));
	}
	$sContent = curl_exec($oCurl);
	$aStatus = curl_getinfo($oCurl);
	curl_close($oCurl);
	if (intval($aStatus["http_code"]) == 200) 
	{
	    return $sContent;
	} 
	else 
	{
	    return FALSE;
	}
}

/**
 * 获取当前页面完整URL地址
 */
function get_url() 
{
    $sys_protocal = isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == '443' ? 'https://' : 'http://';
    $php_self = $_SERVER['PHP_SELF'] ? $_SERVER['PHP_SELF'] : $_SERVER['SCRIPT_NAME'];
    $path_info = isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : '';
    $relate_url = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : $php_self.(isset($_SERVER['QUERY_STRING']) ? '?'.$_SERVER['QUERY_STRING'] : $path_info);
    return $sys_protocal.(isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '').$relate_url;
}
//订单号：项目名称大写字母（BLZ）+年月日（各两位）+uid+时分秒（各两位）+三位微妙
function order_id($user_id) {
    $sec = substr(1000 + microtime() * 1000, 1, 3); //微妙3位
    $str = date('ymd') . $user_id . date('His') . $sec;
    return 'HWJ' . $str;
}

function create_face($pw_length = 8)
{
    $randpwd = '';
    for ($i = 0; $i < $pw_length; $i++) 
    {
        $randpwd .= chr(mt_rand(33, 126));
    }
    return $randpwd;
} 